package com.qiall.omsserver.service.ssh.webssh.controller;

import com.qiall.omsserver.data.entity.ServerInfo;
import com.qiall.omsserver.data.mapper.ServerInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class RouterController {
    @Autowired
    private ServerInfoMapper serverInfoMapper;

    @RequestMapping("/websshpage")
    public String websshpage(Model model, @RequestParam("id") Integer id) {
        ServerInfo serverInfo = serverInfoMapper.select(id);
        String host = serverInfo.getServerHost();
        Integer port = serverInfo.getSshPort();
        String password = serverInfo.getLoginPassword();
        String userName = serverInfo.getLoginName();
        model.addAttribute("host", host);
        model.addAttribute("port", port);
        model.addAttribute("password", password);
        model.addAttribute("userName", userName);
        return "websshPage";
    }

    @RequestMapping("/websshpageWithPassword")
    public String websshpageWithPassword(Model model,
                                         @RequestParam("port") Integer port,
                                         @RequestParam("host") String host,
                                         @RequestParam("userName") String userName,
                                         @RequestParam("password") String password) {
        model.addAttribute("host", host);
        model.addAttribute("port", port);
        model.addAttribute("password", password);
        model.addAttribute("userName", userName);
        return "websshPage";
    }
}
